<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增对战</title>
    <link rel="stylesheet" th:href="@{../static/layui/css/layui.css}" href="/static/layui/css/layui.css" media="all">
</head>
<body>

<form class="layui-form" action="">

    <div class="layui-form-item">
        <label class="layui-form-label">比赛名称</label>
        <div class="layui-input-block">

            <input type="text" name="mname" required lay-verify="required" placeholder="请输入比赛名称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">比赛地点</label>
        <div class="layui-input-block">
            <input type="text" name="matchAddress" required lay-verify="required" placeholder="请输入比赛地点" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">比赛信息</label>
        <div class="layui-input-block">
            <input type="text" name="matchInfo" required lay-verify="required" placeholder="请输入比赛地点" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script th:src="@{../static/layui/layui.js}"></script>
<script th:src="@{../static/js/eleDel.js}" type="text/javascript"></script>
<script th:src="@{../static/mysource/js/jquery-3.3.1.min.js}"></script>
<script>


    //下拉框可能会用到 New option
    //这个里面的参数说明 第一个是显示的文本，第二个是value值
    //例如：new Option(item.xm, item.id)第一个参数是下拉列表中显示的值  第二个参数是选中传递给后台的值
    layui.use(['form', 'upload', 'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;



        // $.ajax({
        //     url: '/match/playInfo',
        //     dataType: 'json',
        //     type: 'get',
        //     success: function (data) {
        //         console.log(data);//下面会提到这个data是什么值
        //         //使用循环遍历，给下拉列表赋值
        //         $.each(data.data, function (index, value) {
        //             // console.log(value.department_id);
        //             $('#first').append(new Option(value.username, value.id));// 下拉菜单里添加元素
        //             $('#second').append(new Option(value.username, value.id));// 下拉菜单里添加元素
        //         });
        //         layui.form.render("select");//重新渲染 固定写法
        //     }
        // })


        // var aid = null;
        // var bid = null;
        // form.on('select(aPlayer)', function (data) {        //对应lay-filter
        //     aid = data.value;//获取value值
        //     // var text= data.elem[data.elem.selectedIndex].text;;    //获取显示的值
        // });
        // form.on('select(bPlayer)', function (data) {        //对应lay-filter
        //     bid = data.value;//获取value值
        //     // var text= data.elem[data.elem.selectedIndex].text;;    //获取显示的值
        // });


        //提交事件
        form.on('submit(formDemo)', function (data) {
            var  mname = $("[name='mname']").val();
            var  matchAddress = $("[name='matchAddress']").val();
            var  matchInfo = $("[name='matchInfo']").val();

            if (mname == ""||matchAddress =="" || matchInfo=="") {
                alert("对战选手不能相同");
                return false;
            }else {
                $.ajax({
                    url: '/game/doAdd',
                    dataType: 'json',
                    type: 'post',
                    data:{"mname":mname,"matchAddress":matchAddress,"matchInfo":matchInfo},
                    success: function (data) {
                        if (data.flag){
                            // alert(data.msg);
                            layer.msg(data.msg,{icon:6})
                            return false
                            // location.reload();
                        }else {
                            alert(data.msg)
                        }
                    }
                })
            }
            // alert(aid + "" + bid)

            return false;
        });


    });


</script>


</body>
</html>